package com.tj.jinzao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.MessageBean;
import com.tj.jinzao.widgets.RoundedImageView;

import java.util.List;

/**
 * Created by LiuYX on 2019/4/22.
 */

public class HeadUserAdapter extends Base_Adapter{
    public HeadUserAdapter(Context context, List list, boolean isFirst) {
        super(context, list, isFirst);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_head_user,null);
            viewHolder.avatar=convertView.findViewById(R.id.avatar);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        MessageBean messageBean= (MessageBean) getItem(position);
        if(messageBean!=null){
            if(messageBean.getUser().getAvatar()!=null&&!messageBean.getUser().getAvatar().equals("")){
                Glide.with(context).load(Constant.IMAGE_PREFIX + messageBean.getUser().getAvatar()).into(viewHolder.avatar);
            }else {
                viewHolder.avatar.setImageResource(R.mipmap.default_head_women);
            }

        }

        return convertView;
    }

    class ViewHolder{
        RoundedImageView avatar;

    }
}
